﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TJDevHouse.Starcraft.AIModuleConnector.ImportExport
{
	/// <summary>
	/// Handles sending the raw game state from the AIModule to the game object
	/// </summary>
	class RawGameStatusImporter
	{
		/// <summary>
		/// Parse the raw game state data and send it to the supplied game object in the expected format.
		/// 
		/// </summary>
		/// <param name="game"></param>
		/// <param name="gameState"></param>
		public void UpdateGameWithStatus(TJDevHouse.Starcraft.Game.Game game, string gameState)
		{
			//format is basically:
			//	status;frame_number;player_statuses;unit_statuses
			int frameNumber;
			string[] playerUpdates, unitUpdates;

			string[] statusBits = gameState.Split(';');

			frameNumber = int.Parse(statusBits[1]);

			playerUpdates = statusBits[2].Split(':');
			unitUpdates = statusBits[3].Split('|');

			game.UpdateGame(frameNumber, playerUpdates, unitUpdates);
		}

	}
}
